/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.una.accidentmanagement.view.manipulator;

import br.com.una.accidentmanagement.bo.TicketController;
import br.com.una.accidentmanagement.model.ActionTicket;
import br.com.una.accidentmanagement.model.Requester;
import br.com.una.accidentmanagement.model.Ticket;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author santosmgbh
 */
public class ActionTable extends DefaultTableModel{
    
    private List<ActionTicket> actions;        
    private Requester requester;

    public ActionTable() {
        actions = new LinkedList<>();
        createColumns();
    }

    public void setRequester(Requester requester) {
        this.requester = requester;
    }        

    public List<ActionTicket> getActions() {        
        return actions;
    }
    
    

    public ActionTable(List<ActionTicket> actions, Requester requester) {
        this.actions = actions;
        this.requester = requester;
        createColumns();
        pushDate();
    }        
    
    private void createColumns(){
        addColumn("Data");
        addColumn("Descrição");
        addColumn("Usuário");        
    }
    
    public void pushDate(ActionTicket t){
        addRow(new RowTicket(t.getActionDate().toString(), t.getDescription(), t.getRequester().getName()));            
        actions.add(t);
    }
    
    
    private void pushDate(){        
        for(ActionTicket t: actions){
            addRow(new RowTicket(t.getActionDate().toString(), t.getDescription(), requester.getName()));            
        }        
    }
    
    class RowTicket extends Vector{        
        RowTicket(String creationDate, String description, String userName) {
            add(creationDate);
            add(description);
            add(userName);        
        }                        
    }
    
    
}
